import * as types from '../mutation-types'

const state = {
  loadingShow: false,
  loadingOptions: {}
}
const getters = {
  loadingShow: state => state.loadingShow,
  loadingOptions: state => state.loadingOptions
}
const actions = {
  showLoading({commit}, {content}) {
    commit(types.SET_LOADING_SHOW, true)
    commit(types.SET_LOADING_OPTIONS, {
      content: content || '正在加载中...'
    })
  },
  closeLoading({commit}) {
    commit(types.SET_LOADING_SHOW, false)
    commit(types.SET_LOADING_OPTIONS, {content: ''})
  }
}
const mutations = {
  [types.SET_LOADING_SHOW](state, flag) {
    state.loadingShow = flag
  },
  [types.SET_LOADING_OPTIONS](state, options) {
    state.loadingOptions = options
  }
}

export default {
  state,
  getters,
  mutations,
  actions
}
